package com.edu.mongodb.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository;

import com.edu.mongodb.dao.BaseMongoDao;

@Repository
public class BaseMongoDaoImpl<T> implements BaseMongoDao{
	
	@Autowired
    private MongoTemplate mongoTemplate;

	@Override
	public <T> List<T> find(Query pQuery, Class<T> pClazz) {
		return mongoTemplate.find(pQuery, pClazz);
	}

	@Override
	public <T> T findOne(Query pQuery, Class<T> pClazz) {
		return mongoTemplate.findOne(pQuery, pClazz);
	}

	@Override
	public <T> void update(Query pQuery, Update pUpdate, Class<T> pClazz) {
		mongoTemplate.upsert(pQuery, pUpdate, pClazz);
	}

	@Override
	public <T> void updatemulti(Query pQuery, Update pUpdate, Class<T> pClazz) {
		mongoTemplate.updateMulti(pQuery, pUpdate, pClazz);
	}

	@Override
	public <T> void save(T pEntity) {
		mongoTemplate.save(pEntity);
	}

	@Override
	public <T> T findById(String pId, Class<T> pClazz) {
		return mongoTemplate.findById(pId, pClazz);
	}

	@Override
	public <T> long count(Query pQuery, Class<T> pClazz) {
		return mongoTemplate.count(pQuery, pClazz);
	}

	@Override
	public <T> void remove(Query pQuery, Class<T> pClazz) {
		mongoTemplate.remove(pQuery,pClazz);
	}

}
